Welcome to Brighton in three hours.
Hello, everyone.
This is lecher for Loop's, conditional on scripts and functions, by the end of this lecture, you
will be able to define for followups in Python, create conditional statements using if anything else,
and create functions in Python.
Let's talk about Loop's, you can create a loop over elements of at least I'm going to first define
a list of integer values, for example, on my list.
Zero one is equal to a list of six integer values.
I'm going to create a second list, which is a list of empty.
This list has no element, but my list to is is still a list to define a loop.
You start with the key for one in space and then a conter and here I named that conter to be inat.
Then you need the key word in and then the list you want your conter to go through its elements.
And that is my list one and then it ends with the column.
So what is expiration means?
Is that in your loop at the beginning, assign the first element of your list one which is three to
your conter.
I not do things that you want to do over the first round of your loop, then go back and then assign
the second element of your list, which is one to your counter, which is enough to do whatever you
want to do over this loop and then assign the next element of your list to your counter.
And you continue until all of your elements of least have been assigned to your counter.
When you create this column here and then just enter, you see that the cursor starts with an indentation
when you have keys, such as for if else, ELIF or DCF, when you want to define a function, you will
see such indentations and these indentations are very important.
And without this indentation you might get error.
So when you define a follow up right after the column, you start with an indentation, one indent,
and then you type whatever you want to do with that indentation.
Let me remove this line.
So as you see here, I start to write some scripts here with some indentation in this particular example.
I want my second list, which initially generated to be empty, to be appended by each element of my
list, but to the power of two.
And this way or the full loop, we see that my list, too, is getting larger and larger because we
are appending China to the power of two to the end of it.
And then here I'm going to print my list.
Then I can see the evolution of this list when this loop goes through, let's run this.
So as you see, I know first is three and then three to the power of two going to be append into the
end of my second list.
So now I have nine.
Then on the second round I have one.
Has I not Piner to the power of two going to be one to the power of two.
I have one and go on until I get the last element of my first list and then my loop is done.
You can create loops using building range function for example.
You can say for your conter I not in range of open and close prentice's and this building function gets
three inputs.
The first input is where we want to start.
The second one is where we want to stop and the last one is our still value.
So what happens in this follow up is that I'm not going to be assigned to be zero, then one, then
two, then three, then four, but five.
And in this example, as you see again, I have indentation and then I'm going to print inat.
I created some separation that's here.
And then I have another loop.
But this time my range starts from three and it to minus 10 ten within still value of minus two.
And then again I'm going to print Einat, let's run this.
So as you see for the first loop, I have zero two for and for the second loop, I have three then because
our step is minus two, the next value is one and it stops at minus nine.
Let's talk about conditional statements.
Conditional statements are going with if elif and ls key values, let's define a variable X here and
then assign forty five to it for a conditional statement you use.
If then here you need a logical explanation which gives you a true or a false.
In this example we want to see if X is divided by two and this percentage is like a built in python
function to compute the remainder of X divided by two.
And if that remain there is zero, then X is divided by two.
If that is true, then I have a column here.
Again, I start with an indentation and then I type here whatever I want to be typed, if this condition
comes through, for example, I say print curly braces is divided by two in single quotations.
And then for curly braces, I'm going to have format and my format going to get X.
If that condition is not true and we want to check other conditions regarding X, then we use Ayliffe.
Now we're going to check if X is divided by three and also if X is divided by five.
As you see here, my ELIF keyboard starts on the same indentation as my IEF.
And then what I wanted to do if my ELIF exploration is true, comes with an indentation right under
it.
For example, if X is divided by three and five at the same time, then I needed to print.
For me, X is not divided by two but is divided by three and five.
If none of these and this condition comes true, we go with LCS and we are going to print here.
We have no comment regarding X if I said X to be 45 and Randy, so then it prints for hours.
Forty five is not divided by two but is divided by three and five.
If I come into this and uncommented this one can run the code for X equals to forty two it says for
the two is divided by two.
Let's come on this and try this four X equals to forty one.
We have no comment regarding forty one.
Let's take a break and then continue to the next part of this lecture.